package com.company;

import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

/**
 * author FJX
 * date 2022年06月17日17:28
 */
public class NGuessNumber {
    public static int[] getPlayerInput() {
        Scanner scanner = new Scanner(System.in);
        int[] number = new int[4];

        int t = 1;
        System.out.println("请输入四个不重复的数字");
        for (int i = 0; i < number.length; i++) {
            System.out.println("第" + (i + 1) + "个数");
            number[i] = scanner.nextInt();
        }

        for (int i = 0; i < number.length; i++) {
            for (int j = 0; j < number.length; j++) {
                if ((number[i] == number[j]) && (j != i)) {
                    t = 1;
                    break;
                } else {
                    t = 0;
                }
            }
            if (t == 1) {
                break;
            }
        }
        if (t == 1) {
            System.out.println("输入了重复的数字，请重新输入");
        }

        return number;
    }
    public static int[] generateAnswer() {
        Random random = new Random();
        int[] guess = new int[4];
        int ran = random.nextInt(10);
        guess[0] = ran;

        for (int i = 0; i < guess.length; i++) {
            ran = random.nextInt(10);
            for (int num = 0; num < i; num++) {
                while (ran == guess[num]) {
                    ran = random.nextInt(10);
                    num = 0;
                }
            }
            guess[i] = ran;
        }
        for (int i = 0; i < guess.length; i++) {
            for (int j = i + 1; j < guess.length; j++) {
                if (guess[i] == guess[j]) {
                    guess[j] = (guess[j] * guess[j] + 1) % 10;
                }
            }
        }

        System.out.println(Arrays.toString(guess));

        return guess;
    }

    public static int compareGuessAnswer(int[] guess, int[] number) {
        int a = 0;
        for (int i = 0; i < guess.length; i++) {
            for (int ignored : number) {
                if (guess[i] == number[i]) {
                    a++;
                    break;
                }
            }
        }
        return a;
    }
}
/* public static boolean isWin(int a) {
        boolean boo;
        boo = a == 4;
        return boo;
    }*/
